import org.apache.commons.io.FileUtils;

import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by 14229 on 2020/2/21.
 */
public class Test06 {
    public static void main(String[] args) throws IOException {

        Map<String, Integer> jiexi = jiexi("b.txt");
        for (String s : jiexi.keySet()) {
            FileUtils.writeStringToFile(new File("c.txt"), s + " : " + jiexi.get(s) + "\n", true);
        }
    }

    public static Map<String, Integer> jiexi(String s) throws IOException {
        Map<String, Integer> map = new HashMap<>();
        //代码填充
        List<String> lines = FileUtils.readLines(new File(s), "UTF-8");
        for (String line : lines) {
            char[] chars = line.toCharArray();
            for (char aChar : chars) {
                String ss = aChar+"";
                Integer count = map.get(ss);
                if (count == null) {
                    count = 1;
                } else {
                    count++;
                }
                map.put(ss, count);
            }
        }
        System.out.println(map);
        return map;
    }

}
